function block = playsound_com(block, flag)
  if flag == 2 then
    channelnum = block.ipar(4);
    buffersize = block.ipar(3);
    index = block.z(1,$); //used buffer size;
    insz = block.insz(1);
    //disp(channelnum, buffersize, index, insz);
    //pause
    if insz + index >= buffersize
      //disp('will play sound')
      //pause
      //copy input to buffer and play sound
      for i = 1:buffersize-index
        for j = 1:channelnum
          block.z(j,index+i) = block.inptr(j)(i);
        end
      end
      fs = block.ipar(1);
      bits = block.ipar(2);
      //disp('before playing sound');
      //pause
      playsnd(block.z(:,1:$-1), fs, bits);
      block.z = zeros(channelnum, buffersize+1);
    else
      //only copy all samples
      //disp('add data')
      //pause
      for i = 1:insz
        for j = 1:channelnum
          block.z(j,index+i) = block.inptr(j)(i);
        end
      end
      block.z(1,$) = index+insz;
    end
  end
endfunction

